import subprocess
import os
import re
import time
from tools import *

LOG = getlogger(__name__)


def main(paramdict, *start_script):
    if 'regx' not in paramdict:
        raise Exception('param_type error')
    if checkprocess(**paramdict):
        LOG.info('process is missing, %s' % str(paramdict))
        ret = timed_start(start_script, 5)
        if ret is None or type(ret) != int:
            raise Exception('RESTART_ERROR')
        elif ret != 0:
            return "RESTART_ERRCODE %d" % ret
        else:
            return "RESTART_OK"
    else:
        return "NOCHANGE"
